home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dragfo / dragform.frm < prev    next >
Text File  |  1995-05-08  |  3KB  |  88 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Dragging Forms And TextBoxes Demo"
  5.    ClientHeight    =   3120
  6.    ClientLeft      =   1320
  7.    ClientTop       =   1905
  8.    ClientWidth     =   4575
  9.    Height          =   3525
  10.    Left            =   1260
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   3120
  15.    ScaleWidth      =   4575
  16.    Top             =   1560
  17.    Width           =   4695
  18.    Begin TextBox Text1 
  19.       Height          =   1820
  20.       Left            =   1440
  21.       MultiLine       =   -1  'True
  22.       TabIndex        =   0
  23.       Text            =   "Text1"
  24.       Top             =   840
  25.       Width           =   1455
  26.    End
  27.    Begin Label Label1 
  28.       Caption         =   "To drag the textbox hold down the control key and press the left mouse button."
  29.       Enabled         =   0   'False
  30.       Height          =   500
  31.       Left            =   480
  32.       TabIndex        =   1
  33.       Top             =   120
  34.       Width           =   3735
  35.    End
  36. End
  37. Sub Form_DragDrop (Source As Control, X As Single, Y As Single)
  38.     Call GetCursorPos(CurPos)
  39.     Call ScreenToClient(Form1.hWnd, CurPos)
  40.         NewPosX% = CurPos.X - MyPosX%
  41.         NewPosY% = CurPos.Y - MyPosY%
  42.     Call MoveWindow(TBhWnd, NewPosX%, NewPosY%, TextBoxRect.Right - TextBoxRect.Left, TextBoxRect.Bottom - TextBoxRect.Top, -1)
  43.     Text1.Dragmode = 0
  44.     Text1.Refresh
  45. End Sub
  46.  
  47. Sub Form_Load ()
  48.     Show
  49.     Text1.SetFocus
  50.     TBhWnd = GetFocus()
  51.     Call GetWindowRect(TBhWnd, TextBoxRect)
  52. End Sub
  53.  
  54. Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  55.       Call GetCursorPos(CurPos)
  56.       Call ScreenToClient(Form1.hWnd, CurPos)
  57.       MyPosX% = CurPos.X
  58.       MyPosY% = CurPos.Y
  59. End Sub
  60.  
  61. Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  62.       If Button = Left_Button And Shift = 0 Then
  63.         Call GetCursorPos(CurPos)
  64.         NewPosX% = CurPos.X - MyPosX%
  65.         NewPosY% = CurPos.Y - MyPosY%
  66.         Call SetWindowPos(Form1.hWnd, 0, NewPosX%, NewPosY%, 0&, 0&, SWP_NOSIZE)
  67.       End If
  68. End Sub
  69.  
  70. Sub Text1_DragDrop (Source As Control, X As Single, Y As Single)
  71.   Form_DragDrop Source, X, Y
  72. End Sub
  73.  
  74. Sub Text1_KeyDown (KeyCode As Integer, Shift As Integer)
  75.     If Shift = 2 Then
  76.         Call GetCursorPos(CurPos)
  77.         Call ScreenToClient(TBhWnd, CurPos)
  78.         MyPosX% = CurPos.X
  79.         MyPosY% = CurPos.Y
  80.         Text1.Dragmode = 1
  81.     End If
  82. End Sub
  83.  
  84. Sub Text1_KeyUp (KeyCode As Integer, Shift As Integer)
  85.    Text1.Dragmode = 0
  86. End Sub
  87.  
  88.